<!--定时发布-->


<form class="form-horizontal ajax-form" action="{:url('Article/setTimingPost')}" method="post" style="margin-left: 40px;margin-right:40px">
    <div class="form-group">
        <label class="control-label">选择时间:</label>
        <div class="col-12">
            <input type="text" name="postTime" autocomplete="off" placeholder="点击输入框选择" class="form-control form-datetime-timing" readonly>
            <span class="help-block m-b-none"></span>
        </div>
    </div>
    <div class="form-group">
        <input type="hidden" class="template_input" name="id" value="{$id}">
        <div class="text-right">
            <button class="ajax-batch-set btn btn-primary" type="submit">确认</button>
        </div>

    </div>
</form>


<script>

    //表单ajax提交
    $(function() {
        //日期控件（定时器）
        $('.form-datetime-timing').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd hh:ii:ss',
            startView: 'month',
            minView: 0,
            autoclose: true,
            todayBtn: true
        });

        if (typeof rules == 'undefined') {
            $("form.ajax-form").each(function () {
                $(this).validate({
                    errorElement : 'div',
                    errorClass : 'help-block',
                    //自定义错误消息放到哪里
                    errorPlacement : function(error, element) {
                        //element.next().remove();//删除显示图标
                        //element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
                        element.closest('.form-group').append(error);//显示错误消息提示
                    },
                    //给未通过验证的元素进行处理
                    highlight : function(element) {
                        $(element).closest('.form-group').addClass('has-error has-feedback');
                    },
                    //验证通过的处理
                    success : function(label) {
                        var el=label.closest('.form-group').find("input");
                        //el.next().remove();//与errorPlacement相似
                        //el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
                        label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
                        label.remove();
                    },
                    submitHandler : function(form) {
                        ajaxFormSubmitFunc(form);
                    }
                });
            });

        } else {
            $("form.ajax-form").each(function() {
                $(this).validate(rules);
            })
        }
    });

    function showTimingPostModel(obj){
        if ($(obj).prop('tagName') == 'LABEL') {
            var ids = getAjaxCheckedValues();
            if (!ids) {
                layer.msg('请选择要操作的文章!', function () {});
                return;
            }
            var id = ids.join(',');
        } else {
            var id = $(obj).data('id');
        }

        layer.open({
            type: 0,
            title: '设定发布时间',
            offset: ['200px'],
            area: ['500px', '250px'],
            btn: [],
            shadeClose: true,
            content: document.getElementById("timing_post_template").innerHTML,
            success: function (layero, index) {
                $('.template_input').val(id);
            }
        });

    }
</script>